﻿using System;
using System.Collections.Generic;
using System.Web;

using OctoOS;
using OctoOS.Services;
using OctoOS.UI;

public partial class samples__post : OOSPage
{
	internal class QueryString
	{
		[QueryStringMember()]
		internal long thread = 0;	// Make the compiler happy

		[QueryStringMember()]
		internal long post = 0;
	}

	protected void Page_Init(object sender, EventArgs e)
	{
		QueryString queryString = EnableQueryString<QueryString>();

		CommentThread thread;
		ICommentService srv = ServiceFactory.GetService<ICommentService>();
		using(srv as IDisposable)
		{
			thread = srv.GetThread(queryString.thread);
		}

		if(null == thread)
		{
			PageTitle = "Post Not Found";

			msgBox.MessageType = MessageBoxType.Error;
			msgBox.SetContent("The requested post has not been found.");
			msgBox.AddLinkButton("OK", "/");
		}
		else
		{
			int pageIndex = TreeThread.GetPostPageIndex(thread, queryString.post, TreeThread.DefaultMinimumPageSize, TreeThread.DefaultOptimumPageSize);

			Response.Redirect(Urls.Classifieds.GetAdDiscussion(queryString.thread, pageIndex, queryString.post));
		}
	}
}